home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FLIGHT / MOUSEMOV.C < prev    next >
Text File  |  1990-01-26  |  4KB  |  188 lines

  1. /*
  2. #include <WindowMgr.h>
  3. #include <Quickdraw.h>
  4. */
  5. #include <math.h>
  6. #include "defines.h"
  7. #include "perspect.h"
  8.  
  9.  
  10. extern    FxVector    fxGrid[GRID_SZ][GRID_SZ];
  11. extern    FxVector    fxGridRot[GRID_SZ][GRID_SZ];
  12. extern    FxVector    fxOriginV;
  13.  
  14. extern    FracThreeMatrx    fracRotatMatrx;
  15. extern    FxThreeMatrx    transpCurrFxRotMatrx;
  16.  
  17. extern    Fract    sinPtOne, cosPtOne, sinPtTwo, cosPtTwo;
  18. extern    Fract    sinNPtOne, cosNPtOne, sinNPtTwo, cosNPtTwo;
  19.  
  20. extern    WindowPtr        theWind;    /*the main window*/
  21.  
  22.  
  23. FxVector    pyramid    = {iToFix(-200), iToFix(-100), iToFix(25)},
  24.             cpyPyramid    = {iToFix(-200), iToFix(-100), iToFix(25)};
  25.  
  26. DoMouseMove(strtClik)
  27. Point    *strtClik;
  28. {
  29. static    int        lookUp[6][6] = 
  30.     {    11,    11,    16,    16,    15,    15,
  31.         11,    12,    13,    13,    14,    15,
  32.         6,    7,    8,    8,    9,    10,
  33.         6,    7,    8,    8,    9,    10,
  34.         0,    3,    4,    4,    5,    2,
  35.         0,    0,    1,    1,    2,    2};
  36.  
  37.     int        hCoord, vCoord;
  38.     Point    clikPt;
  39.  
  40.     clikPt = *strtClik;
  41.  
  42.     while (StillDown())
  43.     {
  44.         hCoord = clikPt.h / 43;
  45.         vCoord = clikPt.v / 43;
  46.  
  47.         SetBack();
  48.         DoMove(lookUp[vCoord][hCoord]);
  49.         GetWind(theWind);
  50.         SetPort(theWind);
  51.         GetMouse(&clikPt);
  52.     }
  53. }
  54.  
  55. DoMove(posCoord)
  56. int        posCoord;
  57. {
  58.  
  59.     register    int    i, j;
  60.     FxVector    tempV, _fxGrid[GRID_SZ][GRID_SZ];
  61.     Point    clikPt;
  62.     FxThreeMatrx    currFxRotMatrx;
  63. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  64.  
  65.     switch    (posCoord) {
  66.     case 0:
  67.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  68.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  69.         break;
  70.     case 1:
  71.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  72.         break;
  73.     case 2:
  74.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  75.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  76.         break;
  77.     case 3:
  78.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  79.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  80.         break;
  81.     case 4:
  82.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  83.         break;
  84.     case 5:
  85.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  86.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  87.         break;
  88.     case 6:
  89.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  90.         break;
  91.     case 7:
  92.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  93.         break;
  94.     case 8:
  95.         DoForward();
  96.         break;
  97.     case 9:
  98.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  99.         break;
  100.     case 10:
  101.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  102.         break;
  103.     case 11:
  104.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  105.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  106.         break;
  107.     case 12:
  108.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  109.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  110.         break;
  111.     case 13:
  112.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  113.         break;
  114.     case 14:
  115.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  116.         break;
  117.     case 15:
  118.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  119.         break;
  120.     case 16:
  121.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  122.         break;
  123.     }
  124.  
  125.     if (posCoord NEQ 8)
  126.     {
  127.         FractToFixMatrx(fracRotatMatrx, currFxRotMatrx);
  128.         FxTranspMatrx(currFxRotMatrx, transpCurrFxRotMatrx);
  129. DoStep();
  130.  
  131.         for (i = 0; i < GRID_SZ; i++)
  132.             for (j = 0; j < GRID_SZ; j++)
  133.             {
  134.                 FxSubtVector(&fxGrid[i][j], &fxOriginV, &tempV);
  135.                 FxMatrxMul(currFxRotMatrx, &tempV, &_fxGrid[i][j]);
  136.             }
  137. FxSubtVector(&pyramid, &fxOriginV, &tempV);
  138. FxMatrxMul(currFxRotMatrx, &tempV, &cpyPyramid);
  139.         EraseRect(&thePort->portRect);
  140.         for (i = 0; i < GRID_SZ; i++)
  141.             FxPlotLine(&_fxGrid[i][0], &_fxGrid[i][GRID_SZ - 1]);
  142.     
  143.         for (j = 0; j < GRID_SZ; j++)
  144.             FxPlotLine(&_fxGrid[0][j], &_fxGrid[GRID_SZ - 1][j]);
  145.         *(FxGridMatrx *)fxGridRot = *(FxGridMatrx *)_fxGrid;    
  146. DrawPyr();
  147.     }
  148. }
  149.  
  150. DoStep()
  151. {
  152. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  153.     FxVector    tempV;
  154.  
  155.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  156.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  157. }
  158.  
  159. DoForward()
  160. {
  161.     FxVector    tempV;
  162.     register    int    i, j;
  163. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  164.  
  165.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  166.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  167.     for (i = 0; i < GRID_SZ; i++)
  168.         for (j = 0; j < GRID_SZ; j++)
  169.             fxGridRot[i][j].x += iToFix(stepSize);
  170. cpyPyramid.x += iToFix(stepSize);
  171.  
  172.     EraseRect(&thePort->portRect);
  173.     for (i = 0; i < GRID_SZ; i++)
  174.         FxPlotLine(&fxGridRot[i][0], &fxGridRot[i][GRID_SZ - 1]);
  175.  
  176.     for (j = 0; j < GRID_SZ; j++)
  177.         FxPlotLine(&fxGridRot[0][j], &fxGridRot[GRID_SZ - 1][j]);
  178. DrawPyr();
  179. }
  180.  
  181. DrawPyr()
  182. {
  183.     FxPlotLine(&fxGridRot[0][0], &cpyPyramid);
  184.     FxPlotLine(&fxGridRot[1][0], &cpyPyramid);
  185.     FxPlotLine(&fxGridRot[0][1], &cpyPyramid);
  186.     FxPlotLine(&fxGridRot[1][1], &cpyPyramid);
  187. }
  188.